"""
Case Type   : CLEAN CONNECTION
Case Name   : CLEAN CONNECTION TO ALL 同时不指定FOR DATABASE和TO USER，合理报错
Create At   : 2022-05-10
Owner       : liu-tong-8848
Description :
    1、执行清理操作
    2、清理环境
Expect      :
    1、执行清理操作，expect: 失败
    2、清理环境，expect: 成功
History     :
"""

import os
import unittest
from yat.test import Node

from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Constant import Constant
from testcase.utils.Logger import Logger


class CleanConnection(unittest.TestCase):

    def setUp(self):
        self.log = Logger()
        self.log.info(f'-----{os.path.basename(__file__)} start-----')
        self.com = Common()
        self.pri_sh = CommonSH('PrimaryDbUser')
        self.pri_root = Node('PrimaryRoot')
        self.constant = Constant()
        self.flag = f'ERROR:  must define Database name or user name'

    def test_main(self):
        step_txt = '----step1: 执行清理操作，expect: 失败----'
        self.log.info(step_txt)
        sql_cmd1 = f'clean connection to all'
        clean_result = self.pri_sh.execut_db_sql(sql_cmd1)
        self.log.info(clean_result)
        self.assertIn(self.flag, clean_result, '执行失败:' + step_txt)

    def tearDown(self):
        self.log.info('----this is teardown----')
        step_txt = '----step2: 清理环境----'
        self.log.info(step_txt)

        self.log.info(f'-----{os.path.basename(__file__)} end-----')
